using System.Data;
using System.Collections;
using Microsoft.VisualBasic;
using System.Diagnostics;
using System;

namespace CustomExcelRenderCS
{
	internal class StyleHandler
	{
		
		private Microsoft.ReportingServices.ReportRendering.Style g_Style;
		internal StyleHandler(Microsoft.ReportingServices.ReportRendering.Style reportStyle)
		{
			g_Style = reportStyle;
		}
		
		internal string GetHtmlStyleString(System.Type t)
		{
			string pStyle = "";
			if (g_Style != null)
			{
				
				pStyle += "font-size:" + g_Style["FontSize"].ToString() + ";";
				pStyle += "font-family:" + g_Style["FontFamily"].ToString() + ";";
				pStyle += "font-style:" + g_Style["FontStyle"].ToString() + ";";
				pStyle += "color:" + this.GetStyleColorRGBCode("Color") + ";";
				if (t == typeof(Microsoft.ReportingServices.ReportRendering.Matrix))
				{
					
					pStyle += "border-color:" + this.GetStyleColorRGBCode("BorderColor") + ";";
					pStyle += "border-width:" + g_Style["BorderWidth"].ToString() + ";";
					pStyle += "border-style:" + g_Style["BorderStyle"].ToString() + ";";
					pStyle += "padding-right:" + g_Style["PaddingRight"].ToString() + ";";
					pStyle += "padding-top:" + g_Style["PaddingTop"].ToString() + ";";
					pStyle += "padding-bottom:" + g_Style["PaddingBottom"].ToString() + ";";
					pStyle += "padding-left:" + g_Style["PaddingLeft"].ToString() + ";";
					pStyle += "background-color:" + this.GetStyleColorRGBCode("BackgroundColor") + ";";
				}
				
			}
			return pStyle;
		}
		
		internal string GetStyleColorRGBCode(string Key)
		{
			if (g_Style[Key] != null && g_Style[Key].GetType() == typeof(Microsoft.ReportingServices.ReportRendering.ReportColor))
			{
				
				System.Drawing.Color c = System.Drawing.Color.FromName(g_Style[Key].ToString());
				return "#" + c.R.ToString("x2") + c.G.ToString("x2") + c.B.ToString("x2");
				
			}
			else
			{
				
				return "";
			}
		}
		
		internal string GetStyleString(string Key)
		{
			if ( g_Style[Key] != null)
			{
				
				return g_Style[Key].ToString();
				
			}
			else
			{
				return "";
			}
		}
		
		internal Microsoft.ReportingServices.ReportRendering.ReportSize GetStyleFontSize()
		{
			if (g_Style["FontSize"] != null)
			{
				return ((Microsoft.ReportingServices.ReportRendering.ReportSize) (g_Style["FontSize"]));
			}
			else
			{
				
				return null;
			}
		}
		
		internal string GetStyleHtmlFontSize(string Key)
		{
			if (g_Style[Key] != null)
			{
				return g_Style[Key].GetType().ToString();
				
			}
			else
			{
				return "";
			}
		}
		
		internal System.Drawing.FontStyle GetStyleFontStyle()
		{
			if (g_Style["FontStyle"] != null)
			{
				
				if (System.Convert.ToString(g_Style["FontStyle"]) == "Italic")
				{
					return System.Drawing.FontStyle.Italic;
					
				}
				else
				{
					return System.Drawing.FontStyle.Regular;
					
				}
			}
			else
			{
				return System.Drawing.FontStyle.Regular;
				
			}
		}
		internal System.Drawing.FontStyle GetStyleFontWeight()
		{
			if (g_Style["FontWeight"] != null)
			{
				
				if (System.Convert.ToString(g_Style["FontWeight"]) == "700")
				{
					
					return System.Drawing.FontStyle.Bold;
					
				}
				else
				{
					
					return System.Drawing.FontStyle.Regular;
					
				}
			}
			else
			{
				
				return System.Drawing.FontStyle.Regular;
				
			}
		}
		internal System.Drawing.ContentAlignment GetStyleTextAlignment()
		{
			
			if ( g_Style["TextAlign"] != null)
			{
				
				if (System.Convert.ToString(g_Style["TextAlign"]) == "Center")
				{
					
					return System.Drawing.ContentAlignment.MiddleCenter;
					
				}
				else if (System.Convert.ToString(g_Style["TextAlign"]) == "Left")
				{
					
					return System.Drawing.ContentAlignment.MiddleLeft;
					
				}
				else if (System.Convert.ToString(g_Style["TextAlign"]) == "Right")
				{
					
					return System.Drawing.ContentAlignment.MiddleRight;
					
				}
				else
				{
					
					return System.Drawing.ContentAlignment.MiddleLeft;
					
				}
			}
			else
			{
				
				return System.Drawing.ContentAlignment.MiddleLeft;
			}
			
		}
	}
	
}
